package com.huasoft.servlet.file;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huasoft.dao.FileDao;
import com.huasoft.dao.UserFileDao;
import com.huasoft.domain.File;
import com.huasoft.domain.UserFile;
/**
 * 部门经理是否同意案卷借出
 * @author Administrator
 *
 */
public class IsAgreeFileServlet {
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserFile userfile = new UserFile();
		userfile.setId(Integer.parseInt(request.getParameter("id")));
		String status=request.getParameter("status");
		status = new String(status.getBytes("iso8859-1"), "gbk");
		userfile.setGiveStatus(status);
		UserFileDao userFileDao = new UserFileDao();
		//部门经理审核案卷方法
		boolean checked = userFileDao.checkedFile(userfile);
		//如果审核成功，则修改案卷的状态
		if (checked == true) {
			FileDao fileDao = new FileDao();
			File file = new File();
			//通过userfile主键获取案卷id
			file.setId(userFileDao.getFileIdById(userfile));
			//如果同意，则把案卷状态改为已借出，否则改为可借阅
			if ("同意".equals(userfile.getGiveStatus())) {
				file.setStatus("已借出");
				request.setAttribute("msg_agreeFileSuccess", "同意案卷借出");
			}else if("不同意".equals(userfile.getGiveStatus())){
				file.setStatus("可借阅");
				request.setAttribute("msg_agreeFileFalse", "不同意案卷借出");
			}
			fileDao.updateStatus(file);
		}else{
			request.setAttribute("msg_agreeFileError", "案卷审核失败");
		}
		request.getRequestDispatcher("/index.jsp").forward(request, response);
	}
}
